package lance.honeydew.action;

import java.io.File;
import java.util.List;

import javax.servlet.ServletContext;

import org.apache.log4j.Logger;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.util.ServletContextAware;

import lance.honeydew.bean.CategoryBig;
import lance.honeydew.bean.OrderInformation;
import lance.honeydew.bean.UserMember;
import lance.honeydew.service.ShopService;
import lance.honeydew.util.MessageUtil;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport implements ServletContextAware {

	private static final Logger logger = Logger.getLogger(BaseAction.class);
	
	/**/
	private UserMember userMemberBo;
	private OrderInformation orderInformationBo;
	
	public UserMember getUserMemberBo() {
		return userMemberBo;
	}

	public void setUserMemberBo(UserMember userMemberBo) {
		this.userMemberBo = userMemberBo;
	}
	
	public OrderInformation getOrderInformationBo() {
		return orderInformationBo;
	}

	public void setOrderInformationBo(OrderInformation orderInformationBo) {
		this.orderInformationBo = orderInformationBo;
	}
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() {
		
		try {
			
			
			
		} catch(Exception e) {
			logger.debug(e);
		}
		
		return SUCCESS;
	}

	/*Pagination*/
	protected static final int pageSize = 10;
	protected int pageNum = 1;
	protected List<String> pageList;
	protected int pageMax = 1;

	public int getPageMax() {
		return pageMax;
	}

	public void setPageMax(int pageMax) {
		this.pageMax = pageMax;
	}

	public List<String> getPageList() {
		return pageList;
	}

	public void setPageList(List<String> pageList) {
		this.pageList = pageList;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public static int getPagesize() {
		return pageSize;
	}
	
	/**
	 * Login User-Session UserMember
	 * setSessionUserMember
	 * @param userMemberBo
	 */
	public void setSessionUserMember(UserMember userMemberBo) {
		SessionMap<String, Object> session = 
				(SessionMap<String, Object>) ActionContext.getContext().getSession();
		
		session.put("LoginUserMember", userMemberBo);
		
	}
	
	/**
	 * Login User-Session UserMember
	 * getSessionUserMember
	 * @return
	 */
	public UserMember getSessionUserMember() {
		SessionMap<String, Object> session = 
				(SessionMap<String, Object>) ActionContext.getContext().getSession();
		
		UserMember loginUserMember = (UserMember) session.get("LoginUserMember");
		
		if (loginUserMember == null) {
			return null;
		} else {
			return loginUserMember;
		}
	}
	
	/*Shopping Car*/
	/**
	 * Shopping Car-Session OrderInformation
	 * setSessionShoppingCar
	 * @param orderInformationBo
	 */
	public void setSessionShoppingCar(OrderInformation orderInformationBo) {
		SessionMap<String, Object> session = 
				(SessionMap<String, Object>) ActionContext.getContext().getSession();
		
		session.put("ShoppingCar", orderInformationBo);
		
	}
	
	/**
	 * Shopping Car-Session OrderInformation
	 * getSessionShoppingCar
	 * @return
	 */
	public OrderInformation getSessionShoppingCar() {
		SessionMap<String, Object> session = 
				(SessionMap<String, Object>) ActionContext.getContext().getSession();
		
		OrderInformation shoppingCar = (OrderInformation) session.get("ShoppingCar");
		
		if (shoppingCar == null) {
			return null;
		} else {
			return shoppingCar;
		}
	}
	
	
	/*File Upload*/
	private File [] file;
    private String [] fileContentType;
    private String [] fileFileName;
    private String filePath;
    
    public ServletContext getContext() {
		return context;
	}

	public void setContext(ServletContext context) {
		this.context = context;
	}

	public String getFilePath() {
		return filePath;
	}

	private ServletContext context;
 
    public File [] getFile() {
        return file;
    }
 
    public void setFile(File [] file) {
        this.file = file;
    }
 
    public String [] getFileContentType() {
        return fileContentType;
    }
 
    public void setFileContentType(String [] fileContentType) {
        this.fileContentType = fileContentType;
    }
 
    public String [] getFileFileName() {
        return fileFileName;
    }
 
    public void setFileFileName(String [] fileFileName) {
        this.fileFileName = fileFileName;
    }
 
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
 
    @Override
    public void setServletContext(ServletContext ctx) {
        this.context=ctx;
    }
    
    /**/
    public int queryReaultMaxSize;

	public int getQueryReaultMaxSize() {
		return queryReaultMaxSize;
	}

	public void setQueryReaultMaxSize(int queryReaultMaxSize) {
		this.queryReaultMaxSize = queryReaultMaxSize;
	}
	
	/*Json Message*/
	protected String jsonMessage;

	public String getJsonMessage() {
		return jsonMessage;
	}

	public void setJsonMessage(String jsonMessage) {
		this.jsonMessage = jsonMessage;
	}
	
	/*photo share path*/
	public String sharePath = MessageUtil.getString("honeydew.filedownload.location");

	public String getSharePath() {
		sharePath = MessageUtil.getString("honeydew.filedownload.location");
		return sharePath;
	}

	public void setSharePath(String sharePath) {
		sharePath = MessageUtil.getString("honeydew.filedownload.location");
		this.sharePath = sharePath;
	}
	
	/*search all*/
	protected String searchAllName;

	public String getSearchAllName() {
		return searchAllName;
	}

	public void setSearchAllName(String searchAllName) {
		this.searchAllName = searchAllName;
	}
	
	
}
